package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.component.util.TimeUtils;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.robottask.RobotTaskConfigDTO;
import com.qumitech.visualnovel.pubdef.dto.script.ScriptRunDTO;
import com.qumitech.visualnovel.service.script.ScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/script")
public class ScriptController {
    @Autowired
    private ScriptService scriptService;

    @PostMapping(value = "/history/run")
    public BaseRsp runHistory(@RequestBody ScriptRunDTO scriptRunDTO) {
        scriptService.start(scriptRunDTO.getStartTime(), scriptRunDTO.getEndTime());
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PostMapping(value = "/test/run")
    public BaseRsp testRun(@RequestBody ScriptRunDTO scriptRunDTO) {
        scriptService.processLogOneDay(TimeUtils.formatDate(scriptRunDTO.getStartTime()));
        return new BaseRsp(ResultEnum.SUCCESS);
    }

}
